package de.lulusoft.anothertorrent.core.rtorrent;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

public class Peer {
	
	public static final String PROP_CHANGED = "peerPROP_CHANGED";
	
	private String address;
	private String client_version;
	private Long completed_percent;
	private Long down_rate;
	private Long down_total;
	private String id;
	private String id_html;
	private String options_str;
	private Long peer_rate;
	private Long peer_total;
	private Long port;
	private Long up_rate;
	private Long up_total;
	private Long encrypted;
	private Long incoming;
	private Long obfuscated;
	private Long snubbed;
	private Torrent torrent;
	
	private PropertyChangeSupport propertyChangeSupport = null;
	private boolean existing = false;
	
	public Peer(String address, String client_version, Long completed_percent,
			Long down_rate, Long down_total, String id, String id_html,
			String options_str, Long peer_rate, Long peer_total, Long port,
			Long up_rate, Long up_total, Long encrypted, Long incoming,
			Long obfuscated, Long snubbed, Torrent torrent, boolean existing) {
		super();
		this.address = address;
		this.client_version = client_version;
		this.completed_percent = completed_percent;
		this.down_rate = down_rate;
		this.down_total = down_total;
		this.id = id;
		this.id_html = id_html;
		this.options_str = options_str;
		this.peer_rate = peer_rate;
		this.peer_total = peer_total;
		this.port = port;
		this.up_rate = up_rate;
		this.up_total = up_total;
		this.encrypted = encrypted;
		this.incoming = incoming;
		this.obfuscated = obfuscated;
		this.snubbed = snubbed;
		this.torrent = torrent;
		this.existing = existing;
		
		propertyChangeSupport = new PropertyChangeSupport(this);
	}
	
	public int update(String address, String client_version, Long completed_percent,
			Long down_rate, Long down_total, String id, String id_html,
			String options_str, Long peer_rate, Long peer_total, Long port,
			Long up_rate, Long up_total, Long encrypted, Long incoming,
			Long obfuscated, Long snubbed, boolean existing) {
		boolean changed = false;
		if (!this.address.equals(address)) { this.address = address; changed = true; }
		if (!this.client_version.equals(client_version)) { this.client_version = client_version; changed = true; }
		if (!this.completed_percent.equals(completed_percent)) { this.completed_percent = completed_percent; changed = true; }
		if (!this.down_rate.equals(down_rate)) { this.down_rate = down_rate; changed = true; }
		if (!this.down_total.equals(down_total)) { this.down_total = down_total; changed = true; }
		if (!this.id.equals(id)) { this.id = id; changed = true; }
		if (!this.id_html.equals(id_html)) { this.id_html = id_html; changed = true; }
		if (!this.options_str.equals(options_str)) { this.options_str = options_str; changed = true; }
		if (!this.peer_rate.equals(peer_rate)) { this.peer_rate = peer_rate; changed = true; }
		if (!this.peer_total.equals(peer_total)) { this.peer_total = peer_total; changed = true; }
		if (!this.port.equals(port)) { this.port = port; changed = true; }
		if (!this.up_rate.equals(up_rate)) { this.up_rate = up_rate; changed = true; }
		if (!this.up_total.equals(up_total)) { this.up_total = up_total; changed = true; }
		if (!this.encrypted.equals(encrypted)) { this.encrypted = encrypted; changed = true; }
		if (!this.incoming.equals(incoming)) { this.incoming = incoming; changed = true; }
		if (!this.obfuscated.equals(obfuscated)) { this.obfuscated = obfuscated; changed = true; }
		if (!this.snubbed.equals(snubbed)) { this.snubbed = snubbed; changed = true; }
		this.existing = existing;
		
		if (changed)
		{	
			return 1;
		}
		else
			return 0;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.address);
	}

	public String getClient_version() {
		return client_version;
	}

	public void setClient_version(String client_version) {
		this.client_version = client_version;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.client_version);
	}

	public Long getCompleted_percent() {
		return completed_percent;
	}

	public void setCompleted_percent(Long completed_percent) {
		this.completed_percent = completed_percent;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.completed_percent);
	}

	public Long getDown_rate() {
		return down_rate;
	}

	public void setDown_rate(Long down_rate) {
		this.down_rate = down_rate;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.down_rate);
	}

	public Long getDown_total() {
		return down_total;
	}

	public void setDown_total(Long down_total) {
		this.down_total = down_total;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.down_total);
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.id);
	}

	public String getId_html() {
		return id_html;
	}

	public void setId_html(String id_html) {
		this.id_html = id_html;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.id_html);
	}

	public String getOptions_str() {
		return options_str;
	}

	public void setOptions_str(String options_str) {
		this.options_str = options_str;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.options_str);
	}

	public Long getPeer_rate() {
		return peer_rate;
	}

	public void setPeer_rate(Long peer_rate) {
		this.peer_rate = peer_rate;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.peer_rate);
	}

	public Long getPeer_total() {
		return peer_total;
	}

	public void setPeer_total(Long peer_total) {
		this.peer_total = peer_total;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.peer_total);
	}

	public Long getPort() {
		return port;
	}

	public void setPort(Long port) {
		this.port = port;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.port);
	}

	public Long getUp_rate() {
		return up_rate;
	}

	public void setUp_rate(Long up_rate) {
		this.up_rate = up_rate;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.up_rate);
	}

	public Long getUp_total() {
		return up_total;
	}

	public void setUp_total(Long up_total) {
		this.up_total = up_total;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.up_total);
	}

	public Long getEncrypted() {
		return encrypted;
	}

	public void setEncrypted(Long encrypted) {
		this.encrypted = encrypted;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.encrypted);
	}

	public Long getIncoming() {
		return incoming;
	}

	public void setIncoming(Long incoming) {
		this.incoming = incoming;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.incoming);
	}

	public Long getObfuscated() {
		return obfuscated;
	}

	public void setObfuscated(Long obfuscated) {
		this.obfuscated = obfuscated;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.obfuscated);
	}

	public Long getSnubbed() {
		return snubbed;
	}

	public void setSnubbed(Long snubbed) {
		this.snubbed = snubbed;
		this.propertyChangeSupport.firePropertyChange(PROP_CHANGED, null, this.snubbed);
	}

	public Torrent getTorrent() {
		return torrent;
	}
	
	public boolean isExisting() {
		return existing;
	}

	public void setExisting(boolean existing) {
		this.existing = existing;
	}

	public void addPropertyChangeListener(PropertyChangeListener listener)
	{
		propertyChangeSupport.addPropertyChangeListener(PROP_CHANGED, listener);
	}
	
	public void removePropertyChangeListener(PropertyChangeListener listener)
	{
		propertyChangeSupport.removePropertyChangeListener(PROP_CHANGED, listener);
	}

}
